package com.atguigu.web.admin.service.impl;

import com.atguigu.commo.exception.StgyException;
import com.atguigu.commo.result.ResultCodeEnum;
import com.atguigu.model.domain.PaymentType;
import com.atguigu.web.admin.service.PaymentTypeService;
import com.atguigu.web.admin.mapper.PaymentTypeMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
* @author Asus
* @description 针对表【payment_type(支付方式表)】的数据库操作Service实现
* @createDate 2024-08-29 14:20:04
*/
@Service
public class PaymentTypeServiceImpl extends ServiceImpl<PaymentTypeMapper, PaymentType>
    implements PaymentTypeService {

    @Override
    public boolean saveOrUpdatePaymentType(PaymentType paymentType) {
        Long id = paymentType.getId()==null?-1:paymentType.getId();
        PaymentType dbPayment = this.getOne(Wrappers.lambdaQuery(PaymentType.class)
                .eq(PaymentType::getName, paymentType.getName())
                .last("limit 1"));
        if (dbPayment !=null&& !id.equals(dbPayment.getId())){
            throw  new StgyException(ResultCodeEnum.PAYMENT_TYPE_EXISTS_ERROR);
        }
        return this.saveOrUpdate(paymentType);
    }
}




